package com.dsjy.yf.address.entity.dataobject;

import com.baomidou.mybatisplus.annotation.TableField;
import com.dsjy.yf.address.service.impl.AddressSplitServiceImpl;
import lombok.Data;

/**
 * @author whj
 * @version 1.0
 * @date 2021-03-11 10:30
 */
@Data
public class BaseDO {
    public Integer parentCode;

    @TableField(select = false)
    private String countyBelong;
    @TableField(select = false)
    private String townBelong;


    /**
     * 我也不知道这样搞合不合适
     *
     * @return
     */
    public Integer getSubCountyCode() {
        if (parentCode != null) {
            return parentCode / 1000;
        }
        return null;
    }

    public String getCountyBelong() {
        if (parentCode != null) {
            if (String.valueOf(parentCode).length() == 9) {
                return AddressSplitServiceImpl.countyCodeMap.get(parentCode / 1000);
            }
            return AddressSplitServiceImpl.countyCodeMap.get(parentCode);
        }
        return null;
    }

    public String getTownBelong() {
        if (parentCode != null && String.valueOf(parentCode).length() == 9) {
            return AddressSplitServiceImpl.townCodeMap.get(parentCode);
        }
        return null;
    }
}
